package csu.rjxyg.action.courseAction;

import java.util.List;

import csu.rjxyg.action.BaseAction;
import csu.rjxyg.action.constant.PermissionConstant;
import csu.rjxyg.action.constant.UserConstant;
import csu.rjxyg.bean.core.BaseList;
import csu.rjxyg.bean.core.BaseObject;
import csu.rjxyg.factory.core.UtilFactory;
import csu.rjxyg.service.BaseCourseService;
import csu.rjxyg.util.LogUtil;

/**
 * @author Jojen
 * 获取课程信息Action
 */
public class GetCourseInfoAction extends BaseAction {
	
	private LogUtil log;
	
	public GetCourseInfoAction() {
		log = UtilFactory.getLogUtil(getClass());
	}
	
	public void getAllCourseInfo() {
		String name = null;

		try {
			BaseCourseService courseService = (BaseCourseService) factory.getBean(BaseAction.COURSE_SERVICE);
			BaseObject object = (BaseObject) this.getSession().get(UserConstant.USER_SESSION);
			name = (String) object.get(UserConstant.USER_ID);
			String QX = (String) object.get(UserConstant.USER_LOGIN_QX);
			BaseList temp;
			if( QX.equals(PermissionConstant.PERMISSION_TEA_JS) ){
				List courseList = (List) object.get(UserConstant.TEACH_COURSE);
				temp = courseService.getBeanInfoById(courseList);
			}else{
				temp = courseService.getAllBeanInfo();
			}
			if( temp == null ){
				return;
			}
			this.out(temp.getBean().toString());
			log.info(name + "查询所有课程信息");
			log.info(temp.getBean().toString());
		} catch (Exception e) {
			log.info(name + "查询所有课程信息失败");
			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
	
	public void getAllCourseInfoByLoginUser() {
		String name = null;

		try {
			BaseCourseService courseSerivce = (BaseCourseService) factory.getBean(BaseAction.COURSE_SERVICE);
			BaseObject object = (BaseObject) this.getSession().get(UserConstant.USER_SESSION);
			name = (String) object.get(UserConstant.USER_ID);

			BaseList temp = courseSerivce.getAllBeanInfo();
			this.out(temp.getBean().toString());
			log.info(name + "查询所有课程信息");
			log.info(temp.getBean().toString());
		} catch (Exception e) {
			log.info(name + "查询所有课程信息失败");
			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
}
